package com.kingbi.system.role.dao;

import java.util.ArrayList;

import com.kingbi.system.role.model.RoleModel;

public class RoleQuery
{
    StringBuilder search_query_bud;

    StringBuilder search_count_bud;

    StringBuilder temp_bud;
    
    Object[] params ;
    
    ArrayList paramList;

    public RoleQuery()
    {
        super();
        this.search_query_bud = new StringBuilder();
        this.search_count_bud = new StringBuilder();
        search_query_bud
                .append("from com.kingbi.system.role.model.RoleModel role where 1=1");
        search_count_bud
                .append("select count(*) from com.kingbi.system.role.model.RoleModel role where 1=1");
    }

    public RoleQuery(StringBuilder search_query_bud, StringBuilder search_count_bud,
            StringBuilder temp_bud)
    {
        super();
        this.search_query_bud = new StringBuilder();
        this.search_count_bud = new StringBuilder();
        search_query_bud
                .append("from com.kingbi.system.role.model.RoleModel role where 1=1");
        search_count_bud
                .append("select count(*) from com.kingbi.system.role.model.RoleModel role where 1=1");
    }

    public void doSearchQuery(RoleModel roleModel)
    {
        temp_bud = new StringBuilder();
        paramList = new ArrayList();
       
             
        if(roleModel.getRoleCode()!=null &&  !roleModel.getRoleCode().equals("") && !roleModel.getRoleCode().equals("null")) 
        { 
                temp_bud.append(" and role.roleCode like ? "); 
                 paramList.add('%'+roleModel.getRoleCode().trim()+'%');
        } 
        if(roleModel.getRoleOrg()!=null &&  !roleModel.getRoleOrg().equals("") && !roleModel.getRoleOrg().equals("null")) 
        { 
                temp_bud.append(" and role.roleOrg=?"); 
                 paramList.add(roleModel.getRoleOrg().trim());
        } 
        if(roleModel.getRoleName()!=null &&  !roleModel.getRoleName().equals("") && !roleModel.getRoleName().equals("null")) 
        { 
                temp_bud.append(" and role.roleName like ? "); 
                 paramList.add('%'+roleModel.getRoleName().trim()+'%');
        } 
      


        if(paramList!=null && paramList.size()>0)
        {
            params = new Object[paramList.size()];
            for(int i=0;i<paramList.size();i++)
            {
                params[i] = paramList.get(i);
            }
        }
        
        if(temp_bud!=null && temp_bud.length()>0)
        {
            search_query_bud.append(temp_bud.toString());
            search_count_bud.append(temp_bud.toString());
        }
       
    }

    public StringBuilder getSearch_query_bud()
    {
        return search_query_bud;
    }

    public void setSearch_query_bud(StringBuilder search_query_bud)
    {
        this.search_query_bud = search_query_bud;
    }

    public StringBuilder getSearch_count_bud()
    {
        return search_count_bud;
    }

    public void setSearch_count_bud(StringBuilder search_count_bud)
    {
        this.search_count_bud = search_count_bud;
    }

    public StringBuilder getTemp_bud()
    {
        return temp_bud;
    }

    public void setTemp_bud(StringBuilder temp_bud)
    {
        this.temp_bud = temp_bud;
    }

    public Object[] getParams()
    {
        return params;
    }

    public void setParams(Object[] params)
    {
        this.params = params;
    }

    
   
}